<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateUserLevelSettingsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('user_level_settings', function (Blueprint $table) {
            $table->id();
            $table->tinyInteger('level')->comment('等级');
            $table->decimal('amount', 18, 2)->default(0)->comment('金额');
            $table->decimal('multiple', 6, 2)->default(0)->comment('积分倍数');
            $table->integer('frequency')->default(0)->comment('拼单资格次数');
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `user_level_settings` comment '用户等级配置'");
        $this->initData();
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('user_level_settings');
    }

    public function initData()
    {
        DB::table('user_level_settings')->insert([
            [
                'level' => 1,
                'amount' => 700,
                'multiple' => 2,
                'frequency' => 3,
                'created_at' => now(),
                'updated_at' => now(),
            ], [
                'level' => 2,
                'amount' => 1400,
                'multiple' => 2.5,
                'frequency' => 5,
                'created_at' => now(),
                'updated_at' => now(),
            ], [
                'level' => 3,
                'amount' => 3500,
                'multiple' => 3,
                'frequency' => 10,
                'created_at' => now(),
                'updated_at' => now(),
            ], [
                'level' => 4,
                'amount' => 7000,
                'multiple' => 3.5,
                'frequency' => 20,
                'created_at' => now(),
                'updated_at' => now(),
            ], [
                'level' => 5,
                'amount' => 14000,
                'multiple' => 4,
                'frequency' => 30,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);
    }
}
